package com.youhome.service.impl;

import com.youhome.mapper.BUserMapper;
import com.youhome.model.BUser;
import com.youhome.service.UserService;
import com.youhome.utils.JwtTokenUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by chen365 on 2018/09/12.
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private BUserMapper bUserMapper;

    @Override
    public BUser selectByPhone(String phone) {
        return bUserMapper.selectByPhone(phone);
    }

    @Override
    public BUser selectByToken(String token) {
        String usernameFromToken = new JwtTokenUtil().getUsernameFromToken(token);
        if (!StringUtils.isEmpty(usernameFromToken)) {
            System.err.println("usernameFromToken:" + usernameFromToken);
            BUser bUser = selectByPhone(usernameFromToken);
            return bUser;
        }
        return null;
    }
}
